﻿// header.h: 标准系统包含文件的包含文件，
// 或特定于项目的包含文件
//

#pragma once
#ifndef FRAMEWORK_H
#define FRAMEWORK_H

#include "targetver.h"
#define WIN32_LEAN_AND_MEAN             // 从 Windows 头文件中排除极少使用的内容
// Windows 头文件
#include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>

#include <tchar.h>
#include <Commctrl.h>

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
//debug
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

// opencv 运行时头文件
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/types_c.h>
#include <opencv.hpp>
#pragma comment(lib, "opencv_world480.lib")
using namespace cv;
// facedetectcnn 运行时头文件
#include "detect/facedetectcnn.h"
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )//不显示控制台

#include "UIgraphics.h"


#define MAX_LOADSTRING 100
#define VEDIOSTREAM_BUFFER_SIZE 0x20000
#define USER_REFREASH_MSG WM_USER+1


//Global varible
bool NeedsDetect = true,isNowActivate = false, isPswShow = false;
int NUM_ALARMTHRESHOLD = 10;
int NUM_ClEARALARM = 4;
int NUM_PAUSETIMER = 100;//ms
float NUM_F_TAN = 0.2f;
bool BOOL_ISDEBUG = false , BOOL_ISBLOCKM = false;
int _count = 0, _dischargeCount = 0;
int BtnWidth = 60, BtnHeight = 30;
string passwordStr,passwordBuf;


//Windows system varible
HWND hwnd, SpmWindow, pswWindow, hBtn[10], hYes, hDel, hTextbox, hCheckBox[2];
HINSTANCE Global_hInstance;
int ScreenWidth, ScreenHeight = 0;
HMENU hmYes = (HMENU)11, hmDel = (HMENU)12;
HHOOK keyrec;

//Use for packing the data to thread 
struct passbyData {
    HWND _hwnd;
    HWND _h_monitor;
};

//Use for packing the data from lib 
struct pRes {
    int Confidence = 0, x = 0, y = 0, w = 0, h = 0;
    int p1 = 0.0, p2 = 0.0, //Lefr eye point
        p3 = 0.0, p4 = 0.0, //Right eye point
        p5 = 0.0, p6 = 0.0, //Nose point
        p7 = 0.0, p8 = 0.0, //Left mouth point
        p9 = 0.0, p10 = 0.0;//Right mouth point
};

//Use for global analysing
struct dMat {
    Mat matPic;
    pRes pMatData;
}frame;

/*通过cv读取视频流*/
VideoCapture cap(0);

//Main Func
bool SideFaceDetect(pRes tempRes, int Square);
bool RectFilter(pRes pRect);
int Detector(/*dMat frame, */HWND hwnd);


//Windows Callback
//extern void RegisterWinClass(LPCSTR lpszClassName, WNDPROC WndProc);


//Painting job
void __onMntrDraw(dMat input_dMat, HDC dc) {
    Mat inputImage;
    Graphics graphics(dc);
    inputImage = input_dMat.matPic;
    cv::line(inputImage, cv::Point(input_dMat.pMatData.p3, input_dMat.pMatData.p4), cv::Point(input_dMat.pMatData.p5, input_dMat.pMatData.p6), Scalar(0, 255, 255, 0), 2, 8, 0);
    cv::line(inputImage, cv::Point(input_dMat.pMatData.p1, input_dMat.pMatData.p2), cv::Point(input_dMat.pMatData.p5, input_dMat.pMatData.p6), Scalar(0, 255, 255, 0), 2, 8, 0);
    cv::line(inputImage, cv::Point(input_dMat.pMatData.p3, input_dMat.pMatData.p4), cv::Point(input_dMat.pMatData.p9, input_dMat.pMatData.p10), Scalar(0, 255, 255, 0), 2, 8, 0);
    cv::line(inputImage, cv::Point(input_dMat.pMatData.p1, input_dMat.pMatData.p2), cv::Point(input_dMat.pMatData.p7, input_dMat.pMatData.p8), Scalar(0, 255, 255, 0), 2, 8, 0);
    cv::Size size = inputImage.size();
    Bitmap _bitmap(size.width, size.height, inputImage.step1(), PixelFormat24bppRGB, inputImage.data);
    graphics.DrawImage(&_bitmap, 0, 0);
    graphics.ReleaseHDC(dc);

}

void __onDraw(HDC dc) {
    Graphics graphics(dc);
    g_printf(&graphics, L"Warning:Security mode activated,please leave the screen", 0, 0, 36, Color(255, 255, 255));
    graphics.ReleaseHDC(dc);
}



#endif // !FRAMEWORK_H